import { ifSourceCodeList, spuMainCodeList } from '@/utils/dictionaries'
// table映射等
export function shineAsk(row, column, cellValue) {
    const data = {
        ifSourceCode: ifSourceCodeList,
        spuMainCode: spuMainCodeList
    }
    const findresult = data[column.property].find(item => item.value === row[column.property])
    if (!findresult) {
      return row[column.property]
    }
    return findresult.label
}

// 给数据新增id值
export function childData(arr, i) {
  arr.map((item, index) => {
    if (item.childrenData) {
      item['id'] = `${index}`
      childData(item['childrenData'], index)
    } else {
      item['id'] = `${i}-${index}`
      return { ...item }
    }
  })
  return arr
}

// input校验
export function inputValidation(value, data) {
  let pattern = ''
  switch (data.spuUnitAcc) {
    case '0' :
      pattern = /^[0-9]\d*$/
      break
    case '1':
      pattern = /^[0-9]+(\.[0-9]{0,1})?$/
      break
    case '2':
      pattern = /^[0-9]+(\.[0-9]{0,2})?$/
      break
    case '3':
      pattern = /^[0-9]+(\.[0-9]{0,3})?$/
      break
    case '4':
      pattern = /^[0-9]+(\.[0-9]{0,3})?$/
  }
    return pattern.test(`${value - 0}`)
}

// 转提示
export const chZnNumber = {
  '0': '零',
  '1': '一',
  '2': '二',
  '3': '三',
  '4': '四',
  '5': '五',
  '6': '六',
  '7': '七',
  '8': '八',
  '9': '九'
}
